﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Chizx.Web.journal
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (null == Session["UserEntity"])
            {
                Response.Redirect("/e/Login.aspx");
            }
            if (Session["UserDegree"].ToString() == "SX")
            {
                Chizx.Model.UserModel umodel = (Chizx.Model.UserModel)Session["UserEntity"];
                this.txtzu_id.Text = umodel.zu_id;
                this.txtzu_id.Enabled = false;
            }    
        }

        		protected void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
            string review_this = "暂无";
            if (Session["UserDegree"].ToString() != "SX")
            {
                review_this = this.txtzj_review.Text;
            }  
			if(this.txtzu_id.Text.Trim().Length==0)
			{
				strErr+="zu_id不能为空！\\n";	
			}
			if(this.txtzj_topic.Text.Trim().Length==0)
			{
				strErr+="zj_topic不能为空！\\n";	
			}
			if(this.txtzj_context.Text.Trim().Length==0)
			{
				strErr+="zj_context不能为空！\\n";	
			}
            if (review_this.Trim().Length == 0)
			{
				strErr+="zj_review不能为空！\\n";	
			}


			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string zu_id=this.txtzu_id.Text;
			string zj_topic=this.txtzj_topic.Text;
			string zj_context=this.txtzj_context.Text;
            string zj_review = review_this;


			Chizx.Model.JournalModel model=new Chizx.Model.JournalModel();
			model.zu_id=zu_id;
			model.zj_topic=zj_topic;
			model.zj_context=zj_context;
            model.zj_createdate = Chizx.Common.DateHelper.getUtcNow();
			model.zj_review=zj_review;
			model.zj_status="j0";

			Chizx.BLL.JournalBll bll=new Chizx.BLL.JournalBll();
			bll.Add(model);
            Chizx.Model.MessageModel mm = new Chizx.Model.MessageModel();
            Chizx.BLL.MessageBll mb = new Chizx.BLL.MessageBll();
            mm.zu_id = zu_id;
            mm.zmsg_topic = "您提交了一篇实习月记";
            mm.zmsg_context = "尊敬的用户 " + zu_id + " ,您好！你刚才提交了一篇实习月记！请等待你的指导老师审核！";
            mm.zmsg_createdate = DateTime.Now;
            mm.zmsg_status = "m0";
            mb.Add(mm);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","add.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
